home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / sendmail / sendmail-5.65c+IDA-1.4.4.1 / src / RCS / flock.c,v < prev    next >
Encoding:
Text File  |  1991-08-16  |  3.4 KB  |  175 lines

  1. head    1.3;
  2. access;
  3. symbols
  4.     RELEASE:1.3
  5.     BETA:1.2;
  6. locks; strict;
  7. comment    @ * @;
  8.  
  9.  
  10. 1.3
  11. date    91.06.21.12.48.43;    author paul;    state Exp;
  12. branches;
  13. next    1.2;
  14.  
  15. 1.2
  16. date    91.05.23.21.32.34;    author paul;    state Exp;
  17. branches;
  18. next    1.1;
  19.  
  20. 1.1
  21. date    91.05.22.18.57.19;    author paul;    state Exp;
  22. branches;
  23. next    ;
  24.  
  25.  
  26. desc
  27. @flock() implemented as either lockf() or fcntl().
  28. @
  29.  
  30.  
  31. 1.3
  32. log
  33. @ANSI changes from Bruce Lilly.
  34. @
  35. text
  36. @/*
  37.  * Copyright (c) 1989 Mark Davies
  38.  * Copyright (c) 1990 Andy Linton
  39.  * Copyright (c) 1990 Victoria University of Wellington.
  40.  * All rights reserved.
  41.  *
  42.  * Redistribution and use in source and binary forms are permitted provided
  43.  * that: (1) source distributions retain this entire copyright notice and
  44.  * comment, and (2) distributions including binaries display the following
  45.  * acknowledgement:  ``This product includes software developed by the
  46.  * Victoria University of Wellington, New Zealand and its contributors''
  47.  * in the documentation or other materials provided with the distribution
  48.  * and in all advertising materials mentioning features or use of this
  49.  * software.
  50.  * Neither the name of the University nor the names of its contributors may
  51.  * be used to endorse or promote products derived from this software without
  52.  * specific prior written permission.
  53.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  54.  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  55.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  56.  */
  57.  
  58. #include "sendmail.h"
  59. #include <errno.h>
  60.  
  61. #ifndef    lint
  62. static char sccsid[] = "%W%";
  63. static char  rcsid[] = "@@(#)$Id: flock.c,v 1.2 1991/05/23 21:32:34 paul Exp paul $";
  64. #endif
  65.   
  66. #if defined(FCNTL_FLOCK) && defined(LOCKF_FLOCK)
  67.     MULTIPLE_FLOCK_REPLACEMENTS_DEFINED
  68. #endif /* FCNTL_FLOCK && LOCKF_FLOCK */
  69.  
  70. #ifdef FCNTL_FLOCK
  71.  
  72. int
  73. flock(fd, operation)
  74. int fd, operation;
  75. {
  76.     int op, ret;
  77.     struct flock arg;
  78.     extern int errno;
  79. # ifdef __STDC__
  80.     extern int fcntl(int, int, ...);
  81. # else /* !__STDC__ */
  82.     extern int fcntl();
  83. # endif /* __STDC__ */
  84.  
  85.     op = (LOCK_NB & operation) ? F_SETLK : F_SETLKW;
  86.     
  87.     arg.l_type = (LOCK_EX & operation) ? F_WRLCK :
  88.         (LOCK_SH & operation) ? F_RDLCK : F_UNLCK;
  89.     arg.l_whence = 0;
  90.     arg.l_start = 0;
  91.     arg.l_len = 0;
  92.     arg.l_pid = 0;
  93.     
  94.     if ((ret = fcntl(fd, op, &arg)) == -1) {
  95.         if (errno == EACCES || errno == EAGAIN)
  96.             errno = EWOULDBLOCK;
  97.     }
  98.     return (ret);
  99. }
  100.  
  101. #endif /* FCNTL_FLOCK */
  102. #ifdef LOCKF_FLOCK
  103.  
  104. int
  105. flock(fd, operation)
  106. int fd, operation;
  107. {
  108.     int op, ret;
  109.     extern int errno;
  110. #ifdef __STDC__
  111.     extern int lockf(int, int, long);
  112. #else /* !__STDC__ */
  113.     extern int lockf();
  114. #endif /* __STDC__ */
  115.  
  116.     op = (LOCK_UN & operation) ? F_ULOCK :
  117.       (LOCK_NB & operation) ? F_TLOCK : F_LOCK;
  118.  
  119.     if ((ret = lockf(fd, op, 0L)) == -1) {
  120.         if (errno == EACCES || errno == EAGAIN)
  121.             errno = EWOULDBLOCK;
  122.     }
  123.  
  124.     return (ret);
  125. }
  126.  
  127. #endif /* LOCKF_FLOCK */
  128. @
  129.  
  130.  
  131. 1.2
  132. log
  133. @Changes for permanent incorporation into the sendmail source directory.
  134. @
  135. text
  136. @d28 1
  137. a28 1
  138. static char  rcsid[] = "@@(#)$Id: flock.c,v 1.1 1991/05/22 18:57:19 paul Exp paul $";
  139. d44 3
  140. d48 1
  141. d75 3
  142. d79 1
  143. d84 1
  144. a84 1
  145.     if ((ret = lockf(fd, op, 0)) == -1) {
  146. @
  147.  
  148.  
  149. 1.1
  150. log
  151. @Initial revision
  152. @
  153. text
  154. @d23 1
  155. a23 2
  156. #include <unistd.h>
  157. #include <sys/types.h>
  158. a24 1
  159. #include "flock.h"               /* defines normally in <sys/file.h> */
  160. d28 1
  161. a28 1
  162. static char  rcsid[] = "@@(#)$Id$";
  163. d31 3
  164. d35 1
  165. a35 1
  166. #if defined(F_SETLK) && defined(F_SETLKW)
  167. d62 2
  168. a63 1
  169. #else
  170. d84 1
  171. a84 2
  172. #endif /* F_SETLK && F_SETLKW */
  173.  
  174. @
  175.